const exp = require('express');

const app = exp();

const data = require('./data/newdata.json');

app.get('/',(req,res)=>{


    res.send('首页');
});


app.get('/list',(req,res)=>{

    let str = ``;


    data.forEach(({newsTitle,id})=>{
        // console.log(item);
        str+=`<p><a href="/detail/${id}.html">${newsTitle}</a></p>`;
    })


    res.send(str);
});

app.get('/detail/:id.html',(req,res)=>{

    let {id} = req.params;

    let {newsTitle,newsContent} = data.find((item)=>item.id===id);

    let str = `
        <h3>${newsTitle}</h3>
        <p>${newsContent}</p>
    `;

    res.send(str);

});


app.listen(80,()=>{
    console.log("成功");
});